/**
 * @param {number} num
 * @return {number}
 */
 var smallestNumber = function(num) {
  let flag = num < 0
  num = Math.abs(num)
  const arr = String(num).split('').map(v=>Number(v)).sort((a,b) => a-b).map(v=>String(v))
  let ans = '', zero = 0
  if(flag){
    return -1 * Number(arr.reverse().join(''))
  }
  for(let i = 0; i<arr.length; i++){
    if(arr[i] === '0'){
      zero++
    }else{
      ans += arr[i]
      if(zero){
        ans += '0'.repeat(zero)
        zero = 0
      }
      
    }
  }
  return Number(ans)
};